/*
* @Author: Josh
* @Date:   2019-01-24 16:00:24
* @Last Modified by:   Administrator
* @Last Modified time: 2019-04-13 17:52:59
*/

'use strict';
require('./index.css');
var _mall         = require('util/mall.js'),
    templateIndex = require('./index.string');

// 侧边导航
var navSide = {
    option : {
        name    : '',
        navList : [
            {name : 'user-center', desc : '我的Mall', href : './user-center.html'},
            {name : 'order-list', desc : '我的订单', href : './order-list.html'},
            {name : 'user-pass-update', desc : '修改密码', href : './user-pass-update.html'},
            {name : 'about', desc : '关于JoshMall', href : './about.html'}
        ]
    },
    init : function(option){
        //合并选项 以第一个参数为模板
        $.extend(this.option, option);
        this.renderNav();
    },
    //渲染导航菜单
    renderNav : function(){
        //计算active数据
        for(var i = 0, iLength = this.option.navList.length; i < iLength ; i++){
            //为调用navSide的页面的名字添加isActive属性
            if(this.option.navList[i].name === this.option.name){
                this.option.navList[i].isActive = true;
            }
        }
        //渲染list数据
       var navHtml = _mall.renderHtml(templateIndex, {
            navList : this.option.navList
        });
        //把html放入容器
        $('.nav-side').html(navHtml);

    }
};

module.exports = navSide;
